package com.knight.hadoop.day08.flow.sort;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.WritableComparable;

public class FlowModel implements WritableComparable<FlowModel>{
	
	private Long upFlow;//上行流量
	private Long dwFlow;//下行流量
	private Long sumFlow;//总流量
	
	
	public Long getSumFlow() {
		return sumFlow;
	}

	public FlowModel() {}

	@Override
	public String toString() {
		return "upFlow=" + upFlow + "\t dwFlow=" + dwFlow + "\t sumFlow="+(upFlow+dwFlow);
	}

	public FlowModel(Long upFlow, Long dwFlow) {
		this.upFlow = upFlow;
		this.dwFlow = dwFlow;
	}
	
	public void set(Long upFlow,Long dwFlow){
		this.upFlow = upFlow;
		this.dwFlow = dwFlow;
		this.sumFlow = (upFlow+dwFlow);
	}
	
	public Long getUpFlow() {
		return upFlow;
	}
	public void setUpFlow(Long upFlow) {
		this.upFlow = upFlow;
	}
	public Long getDwFlow() {
		return dwFlow;
	}
	public void setDwFlow(Long dwFlow) {
		this.dwFlow = dwFlow;
	}
	
	/**
	 * 按顺序写
	 */
	@Override
	public void write(DataOutput out) throws IOException {
		out.writeLong(upFlow);
		out.writeLong(dwFlow);
		out.writeLong(sumFlow);
	}
	/**
	 * 按顺序读
	 */
	@Override
	public void readFields(DataInput in) throws IOException {
		upFlow = in.readLong();
		dwFlow = in.readLong();
		sumFlow = in.readLong();
	}

	@Override
	public int compareTo(FlowModel o) {
		return this.getSumFlow() > o.getSumFlow() ? -1 : 1;
	}
}
